<?php
namespace app\common\order\model;

use app\common\product\logic\ProduceLogic;
use app\common\product\logic\StoreCategoryLogic;
use app\common\product\logic\StoreSupplierLogic;
use app\common\system\logic\UserLogic;
use think\Model;
use think\model\concern\SoftDelete;

class OrderFour extends Model
{
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $type = [
        'meet_time' => 'timestamp',
    ];

    public function getUserAttr($value, $data) {
        $userLogic = new UserLogic();
        return $userLogic->getUser($data['user_id'], ['id', 'realname', 'status']);
    }

    public function getCategoryAttr($value, $data)
    {
        $logic = new StoreCategoryLogic();
        return $logic->getStoreCategory($data['category_id'], ['id', 'title']);
    }

    public function getSupplierAttr($value, $data)
    {
        if (empty($data['supplier_id'])) {
            return [
                "id" => "",
                "title" => ""
            ];
        }

        $logic = new StoreSupplierLogic();
        return $logic->getStoreSupplier($data['supplier_id'], ['id', 'title']);
    }

    public function getProductAttr($value, $data)
    {
        $logic = new ProduceLogic();
        return $logic->getProduce($data['product_id'], ['id', 'title', 'price']);
    }
}